package c.m.d.b.beans;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import java.io.Serializable;

@Entity
@Table(name = "PROP_TYPE")
public final class PropertyType implements Serializable
{
    private static final long serialVersionUID = 1L;

    @EmbeddedId
    private final PropertyTypePK key = new PropertyTypePK();

    @Column(name = "DATA_TYPE", nullable = false)
    private DataType dataType;

    @Column(name = "MANDATORY")
    private boolean mandatory;

    public String getPropertyTypeName()
    {
        return key.getPropertyTypeName();
    }

    public void setPropertyTypeName(String propertyTypeName)
    {
        this.key.setPropertyTypeName(propertyTypeName);
    }

    public void setEntityTypeName(String entityTypeName)
    {
        this.key.setEntityTypeName(entityTypeName);
    }

    public String getEntityTypeName()
    {
        return this.key.getEntityTypeName();
    }


    public DataType getDataType()
    {
        return dataType;
    }

    public void setDataType(DataType dataType)
    {
        this.dataType = dataType;
    }

    public boolean isMandatory()
    {
        return mandatory;
    }

    public void setMandatory(boolean mandatory)
    {
        this.mandatory = mandatory;
    }

    @Override
    public int hashCode()
    {
        int result = key.getEntityTypeName().hashCode();
        result = 31 * result + key.getPropertyTypeName().hashCode();
        result = 31 * result + (mandatory ? 1231 : 1237);
        return result;
    }

    @Override
    public boolean equals(Object obj)
    {
        if (this == obj)
        {
            return true;
        }

        if (obj == null || getClass() != obj.getClass())
        {
            return false;
        }

        PropertyType that = (PropertyType) obj;

        if (!key.getEntityTypeName().equals(that.getEntityTypeName()))
        {
            return false;
        }

        if (!key.getPropertyTypeName().equals(that.getPropertyTypeName()))
        {
            return false;
        }

        return true;
    }
}
